package com.icangya.DAO.impl;

import com.icangya.DAO.IAdvertClickDAO;
import com.icangya.domain.AdvertClick;
import org.springframework.stereotype.Repository;

@Repository
public class AdvertClickDAOImpl  extends BaseDAO<AdvertClick> implements IAdvertClickDAO{


    @Override
    public Double getAdvertClickMoney(Long advertId) {

        String hql="select sum(ad.clickMoney) from AdvertClick ad where ad.advertId=?";
        Double sumMoney= (Double) getHibernateTemplate().find(hql,advertId).get(0);
        return sumMoney;
    }

    @Override
    public boolean getAdvertClickByOpenId(String openId, Long advertId) {

        String hql = "FROM AdvertClick ad where ad.advertId=? and ad.openId=?" ;
        String count = "SELECT COUNT(ad) " + hql;
        Long total = (Long) (getHibernateTemplate().find(count,advertId,openId).get(0));//总的记录条数

        if(total>0)
        return false;
        return true;
    }

    @Override
    public Long getCountAdvertClick(Long advertId) {

        String hql="select count(ad) from AdvertClick ad where ad.advertId=?";

        return (Long)getHibernateTemplate().find(hql,advertId).get(0);
    }


}
